package com.gitee.kamismile.stone.basic.data.infrastructure.utils;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.data.r2dbc.core.R2dbcEntityTemplate;
import org.springframework.data.r2dbc.core.ReactiveSelectOperation;
import org.springframework.data.relational.core.query.Criteria;
import reactor.core.publisher.Mono;
import reactor.util.function.Tuple2;

import java.util.List;
import java.util.function.Function;

import static org.springframework.data.relational.core.query.Query.query;

public class QueryBuilder<T> {

    private final R2dbcEntityTemplate template;
    private final Class<T> clz;
    private Criteria criteria;

    public QueryBuilder(R2dbcEntityTemplate template, Class<T> clz) {
        this.template = template;
        this.clz = clz;
    }

    public QueryBuilder<T> where(Criteria criteria) {
        this.criteria = criteria;
        return this;
    }



    public ReactiveSelectOperation.TerminatingSelect apply() {
        return select();
    }


    private ReactiveSelectOperation.TerminatingSelect select() {
        return template.select(clz)
                .matching(query(criteria));
    }





}
